<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        姓名：<input type="text" v-model="form.name">
        性别：<input type="radio" v-model='form.sex' value="1" :disabled='form.isDisabled'>男
             <input type="radio" v-model='form.sex' value="2" :disabled='form.isDisabled'>女
        年龄：<input type="text" v-model="form.age" :disabled='form.isDisabled'>
    </div>
    <script src="../vue.js"></script>
    <script>
        new Vue({
            el:'#app',
            data () {
                return {
                    form:{
                        name:'',
                        sex:'',
                        age:'',
                        isDisabled:true,
                    }
                }
            },
            watch: {
                form:{
                    handler(newVal){
                        console.log(newVal.name);
                        for (const key in newVal) {
                            if (!newVal[key]) {
                                console.log(key+'没有值');
                            }
                        }
                        if(newVal.name=='张大欣'){
                            newVal.sex=2;
                            newVal.age=21;
                            newVal.isDisabled=false;
                            console.log(newVal);
                        }
                        else if(!newVal.name){
                            newVal.sex='';
                            newVal.age='';
                            newVal.isDisabled=true;
                        }
                    },
                    deep:true,
                    immediate:true,
                }
            },
        })
    </script>
</body>
</html>